<?php 

function getImgPath($src){
	if ($src) {
		return APP_DOMAIN.$src;
	}
	return '';
}

function frm_out_put($arr,$nm,$tag,$value='',$js="",$firstNode=""){

	$value=trim($value);
	switch($tag){
		case 'option':
			$str="<select name='".$nm."' id='".$nm."' ".$js." >\n";
			if($firstNode){
				$str.="\t<option value=''>".$firstNode."</option>\n";
			}
			foreach ($arr as $k => $v) {
				if($value==$k&&$value!=''){
					$str .= "\t<$tag value='$k' selected>$v</$tag>\n";
				}else{
					$str .= "\t<$tag value='$k' $defaultCk>$v</$tag>\n";
				}
			}
			$str.="</select>";
			break;

		case 'radio':
			$i=0;
			foreach ($arr as $k => $v) {
				if($value==$k&&$value!=''){
					$str .= "\n<span><input type='".$tag."' name='".$nm."' id='".$nm.$k."' class='radio' checked='checked' value='".$k."' ".$js."> <label for='".$nm.$k."'>".$v."</label></input></span>\n ";
				}else{
					if($i==0 && $value==''){$defaultCk = 'checked';$i++;}
					$str .= "\n<span><input type='".$tag."' name='".$nm."' id='".$nm.$k."' class='radio' value='".$k."' ".$js." $defaultCk> <label for='".$nm.$k."'>".$v."</label></input></span>\n ";
					$defaultCk='';
				}
			}
			break;

		case 'checkbox':
			if($value)
				$arrValue = explode(',',$value);
			else
				$arrValue = array();
			$checkTag=0;
			foreach ($arr as $k => $v) {
				for($i=0;$i<count($arrValue);$i++){
					if($arrValue[$i]==$k&&$value!=''){
						$str .= "\n<span><input type='".$tag."' name='".$nm."[]' value='".$k."' checked='checked' ".$js.">".$v."</input></span>\n";
						$checkTag++;
					}
				}
				if($checkTag==0){
					$str .= "\n<span><input type='".$tag."' name='".$nm."[]' value='".$k."' ".$js.">".$v."</input></span>\n";
				}
				$checkTag=0;
			}
			break;
	}
	return $str;
}

function returnJson($status=0,$data=array(),$msg=''){
    $ret = array('status'=>$status,'data'=>$data,'msg'=>$msg);
    return json_encode($ret);
}

function getExpress($format = false,$status=1){
    if($status){
        $list = M('Express')->where(array('status'=>1))->select();
    }else{
        $list = M('Express')->select();
    }
    $ret = array();
    if($format) {
        foreach($list as $v){
            $ret[$v['id']] = $v['title'];
        }
    }else{
        $ret = &$list;
    }
    return $ret;
}

function getAllRoles($format = false){
    $list = M('Role')->select();
    $ret = array();
    if($format) {
        foreach($list as $v){
            $ret[$v['id']] = $v['name'];
        }
    }else{
        $ret = &$list;
    }
    return $ret;
}

function getRoleAuth(){
    $list = M('Role')->select();
    $ret = array();
    foreach($list as $v){
        $ret[$v['id']] = $v['auth'];
    }
    return $ret;
}
?>